package com.modificial.shiro.system.dao;

import com.modificial.shiro.mapper.BaseMapper;
import com.modificial.shiro.system.domain.SysPermission;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author modificial
 * @date 2018/8/4 0004
 * @company modificial_org
 * @description 权限操作
 */
@Repository
public interface PermissionDao extends BaseMapper<SysPermission> {
    /**
     * 根据角色查询权限
     * @param roleId 角色id
     * @return
     */
    @Select("select T1.permission from sys_permission T1 left join sys_role_permission T2 " +
            "on T1.permission_id=T2.permission_id and T2.role_id=#{roleId}")
    List<String> findPermissionsByRole(String roleId);

    /**
     * 更新权限信息
     * @param sysPermission
     * @return
     */
    @Update("update sys_permission set permission_name=#{permissionName},url=#{url},icon=#{icon}," +
            "description=#{description},update_time=now(),sort=#{sort},permission=#{permission} where permission_id=#{permissionId}")
    int updatePermission(SysPermission sysPermission);
}
